package com.framework.base.taglib.ui;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import com.framework.base.util.StringUtil;

/**
 * @Description:功能描述：IE打印标签 
 *                          要打印的表格要加:id="sortTable",也可以定义id="printArea"的一个隐藏div,div内容为打印的内容
 *                          。如果两个都定义，则打印id="printArea"的内容,涉及到print.js,print.htm
 * @Company: framework
 * @author：刘明云
 * @version 1.0
 * @Date 2011-6-29 下午02:21:00
 */
public class PrintTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3103579398428630101L;
	private String value;// 打印按钮显示的值
	private String onclick;// 打印的事件
	private String printTableTitle;// 打印页面要显示的标题
	private int startPrintColumn;// 开始打印的列
	private int endPrintColumn;// 结束打印的列

	public int doStartTag() throws JspException {
		String context = ((HttpServletRequest) pageContext.getRequest())
				.getContextPath();
		JspWriter out = pageContext.getOut();
		try {
			if (StringUtil.isNullorEmpty(value)) {
				value = "打印";
			}
			if (StringUtil.isNullorEmpty(onclick)) {
				onclick = "iePrint()";
			}
			if (StringUtil.isNullorEmpty(printTableTitle)) {
				printTableTitle = "";
			}
			out.write("<input type=\"button\" class=\"sysbutton\" value=\""
					+ value + "\" onclick=\"" + onclick + "\">");
			out
					.write("<input id=\"printTableTitle\" name=\"printTableTitle\" type=\"hidden\" value=\""
							+ printTableTitle + "\">");
			out
					.write("<input id=\"startPrintColumn\" name=\"startPrintColumn\" type=\"hidden\" value=\""
							+ startPrintColumn + "\">");
			if (endPrintColumn != 0) {
				out
						.write("<input id=\"endPrintColumn\" name=\"endPrintColumn\" type=\"hidden\" value=\""
								+ endPrintColumn + "\">");
			}
			out.write("<script type=\"text/javascript\" src=\"" + context
					+ "/common/js/print.js\"></script>");

		} catch (Exception e) {
			e.printStackTrace();
			throw new JspException("错误信息: 在生成打印标签时出错");
		}
		return super.doStartTag();
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	public String getOnclick() {
		return onclick;
	}

	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	public String getPrintTableTitle() {
		return printTableTitle;
	}

	public void setPrintTableTitle(String printTableTitle) {
		this.printTableTitle = printTableTitle;
	}

	public int getStartPrintColumn() {
		return startPrintColumn;
	}

	public void setStartPrintColumn(int startPrintColumn) {
		this.startPrintColumn = startPrintColumn;
	}

	public int getEndPrintColumn() {
		return endPrintColumn;
	}

	public void setEndPrintColumn(int endPrintColumn) {
		this.endPrintColumn = endPrintColumn;
	}

}
